package com.jiantong.news.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 养殖智库视频
 * Created by mz03 on 2017/4/12.
 */
@Data
public class ThinktankVideo implements Serializable{

    private static final long serialVersionUID = 2674290635820773537L;
    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();



    /**
     * id
     */
    private Long id;


    /**
     * 标题
     */
    private String title;


    /**
     * 类型
     */
    private Integer type;


    /**
     * 描述
     */
    private String content;


    /**
     * 视频快照
     */
    private String snapshoot;


    /**
     * 视频快照
     */
    private Map<String , Map<String , String>> snapshootMap;


    /**
     * 视频
     */
    private String video;


    /**
     * 状态, 1: 正常, -1: 删除
     */
    private Integer status;


    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     *
     */
    private Date updatedAt;


    public void setSnapshoot(String snapshoot){
        this.snapshoot = snapshoot;
        if(Strings.isNullOrEmpty(snapshoot)){
            this.snapshootMap = Maps.newHashMap();;
        }else {
            try {
                this.snapshootMap = objectMapper.readValue(snapshoot, new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setPicMap(Map<String , Map<String , String>> snapshootMap){
        this.snapshootMap = snapshootMap;
        if(snapshootMap == null || snapshootMap.isEmpty()){
            this.snapshoot = null;
        }else {
            try {
                this.snapshoot = objectMapper.writeValueAsString(snapshootMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck IOException
            }
        }
    }


}
